import { route, GET, POST } from 'awilix-express';

@route('/ipl')
export default class IplApi {

  constructor({ iplService }) {
    this.iplService = iplService;
  }

  // 获取一个IP
  @route('/getIplOne')
  @GET()
  async getIplOne(req, res){
    const { success, data: list, message } = await this.iplService.getIplOne();
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message, list);
  }

  // 根据IP删除对应数据
  @route('/delByIp')
  @POST()
  async delByIp(req, res){
    const { t_ipl } = req.body;
    const { success, message } = await this.iplService.delByIp({t_ipl});
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message);
  }

  // 批量添加
  @route('/bulkIpls')
  @POST()
  async bulkIpls(req, res) {
    const { ipls } = req.body;
    const { success, message } = await this.iplService.bulkIpls(ipls);
    if (!success) {
      res.failPrint(message);
      return;
    }
    res.successPrint(message);
  }
}